/*
 *
 * Copyright(c) 2010 Safelayer Secure Communications
 *
 * This is open source software, placed under the terms of the
 * GNU GENERAL PUBLIC LICENSE Version 3.
 * Please see: http://www.gnu.org/licenses/gpl-3.0.txt
 * 
 * Permission to use, copy, modify, and distribute this software
 * for any purpose and without fee is hereby granted, provided
 * that the above copyright notices appear in all copies and that
 * both the copyright notice and this permission notice appear in
 * supporting documentation.
 * 
 */
package com.neuralnoise.foaf.core;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
 * Models a FOAF Organization. The Organization class represents a kind of {@link Agent}
 * corresponding to social instititutions such as companies, societies etc. This is a more 'solid'
 * class than {@link Group}, which allows for more ad-hoc collections of individuals.
 * <p>
 * For more info see FOAF Vocabulary Specification
 * 
 * @author victor.martinez <swtp@safelayer.com>
 */
public class Organization extends Agent {

	private Set<Agent> memberSet = new LinkedHashSet<Agent>();

	public Organization(String uri) {
		super(uri);
	}

	public Organization() {
		super(null);
	}

	/**
	 * Returns all members.
	 * 
	 * @return Returns all members.
	 */
	public List<Agent> getAllMembers() {
		return new ArrayList<Agent>(memberSet);
	}

	/**
	 * Adds the specified <code>member</code> to this {@link Organization} if it is not already
	 * present.
	 * 
	 * @param member The <code>member</code> to be added to this <code>Organization</code> .
	 * @return <tt>true</tt> if the <code>Organization</code>. did not already contain the specified
	 *         <code>member</code>
	 */
	public boolean addMember(Agent member) {
		return memberSet.add(member);
	}

	/**
	 * Removes the specified <code>member</code> from this {@link Organization}, if it is present.
	 * Returns <tt>true</tt> if this <code>Organization</code> contained the specified
	 * <code>member</code> (or equivalently, if this <code>Organization</code> changed as a result
	 * of the call).
	 * 
	 * @param member The <code>member</code> to be removed from this <code>Organization</code>.
	 * @return <tt>true</tt> if this <code>Organization</code> contained the specified
	 *         <code>member</code>
	 */
	public boolean removeMember(Agent member) {
		return memberSet.remove(member);
	}

	/**
	 * Removes all of the members from this {@link Organization}. The members from
	 * <code>Organization</code> will be empty after this call returns.
	 */
	public void clearMembers() {
		memberSet.clear();
	}

	/**
	 * Returns <tt>true</tt> if this {@link Organization} contains the specified <code>member</code>
	 * 
	 * @param member The <code>member</code> whose presence in this <code>Organization</code> is to
	 *            be tested.
	 * @return <tt>true</tt> if this <code>Organization</code> contains the specified
	 *         <code>member</code>
	 */
	public boolean containsMember(Agent member) {
		return memberSet.contains(member);
	}
}
